package cn.hp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.hp.domain.Role;
import cn.hp.service.RoleService;

@Controller
@RequestMapping("/role")
@Secured({"ROLE_ADMIN"})
public class RoleController {
	
	@Autowired
	private RoleService roleService;
	
	
	//查询所有角色
	@RequestMapping("/findAll")
	public ModelAndView findAll(){
		List<Role> roleList=roleService.findAll();
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("roleList", roleList);
		modelAndView.setViewName("role-list");
		return modelAndView;
	}
	
	
	//添加角色
	@RequestMapping("/save")
	public String save(Role role){
		roleService.save(role );
		return "redirect:findAll";
	}
	
	
}
